]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
slider: Add a step() method
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 29 Aug 2025 21:36:32 +0000 (23:36 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 29 Aug 2025 22:55:47 +0000 (00:55 +0200)
This method takes a (possibly fractional) number of scroll steps,
and converts it to the right amount to move the slider value.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3842>

js/ui/slider.js

index 3b0a3b7cf3dd68aa83a233ab89f744633005dd43..ebd181e3760a7ca8d4c48d99d908f9ad888dc2b7 100644 (file)
@@ -148,26 +148,38 @@ export const Slider = GObject.registerClass({
         return Clutter.EVENT_PROPAGATE;
     }
 
+    step(nSteps) {
+        const delta = nSteps * SLIDER_SCROLL_STEP;
+        const value = Math.min(Math.max(0, this._value + delta), this._maxValue);
+
+        if (value !== this.value) {
+            this.value = value;
+            return true;
+        }
+
+        return false;
+    }
+
     scroll(event) {
         let direction = event.get_scroll_direction();
-        let delta = 0;
+        let nSteps = 0;
 
         if (event.get_flags() & Clutter.EventFlags.FLAG_POINTER_EMULATED)
             return Clutter.EVENT_PROPAGATE;
 
         if (direction === Clutter.ScrollDirection.DOWN) {
-            delta = -SLIDER_SCROLL_STEP;
+            nSteps = -1;
         } else if (direction === Clutter.ScrollDirection.UP) {
-            delta = SLIDER_SCROLL_STEP;
+            nSteps = 1;
         } else if (direction === Clutter.ScrollDirection.SMOOTH) {
             let [dx] = event.get_scroll_delta();
-            delta = dx * SLIDER_SCROLL_STEP;
+            nSteps = dx;
             // Match physical direction
             if (event.get_scroll_flags() & Clutter.ScrollFlags.INVERTED)
-                delta *= -1;
+                nSteps *= -1;
         }
 
-        this.value = Math.min(Math.max(0, this._value + delta), this._maxValue);
+        this.step(nSteps);
 
         return Clutter.EVENT_STOP;
     }